import React from 'react';
import { inject, observer } from 'mobx-react';
import { Button, Modal, Rate, Tabs, Spin } from 'antd';
import { toJS } from 'mobx';
import { WeaTableNew, WeaSwitch, WeaForm } from 'comsMobx';

const WeaTable = WeaTableNew.WeaTable;
import { WeaTag, WeaRightMenu, WeaTop, WeaTab, WeaErrorPage, WeaTools, WeaNewScroll, WeaSelect, WeaDialog, WeaTransfer, WeaAlertPage, WeaLocaleProvider, WeaFormItem, WeaSearchGroup } from 'ecCom';
import WeaRightLeftLayout from './comp/weaCrmRightLeft';
import WeaCrmTab from './comp/weaCrmTab';
import WeaDropdown from './comp/weaCrmDropdown';

const ButtonGroup = Button.Group;
const TabPane = Tabs.TabPane;
import SetTagModal from './public/SetTagModal';
import ViewContactLog from './public/ViewContactLog';
import ViewContacter from './public/ViewContacter';
import ViewLeaveMessage from './public/ViewLeaveMessage';
import ViewSellChance from './public/ViewSellChance';
import CardManage from './card/cardManage';
import Condition from './list/customCondition';

const getLabel = WeaLocaleProvider.getLabel;

@inject('mineCustomerStore')
@observer
class MineCustomer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      showSearchAd: false,
    };
  }
  componentDidMount() {
    const { mineCustomerStore } = this.props;
    const { getMyCustomerTabs, doSearch, getRemindCount, getMyCustomerTagsList, conditionTop, getContactLogs, getSeasRight, getSearchAdForm } = mineCustomerStore;
    getMyCustomerTabs(); // 获取tab页签
    conditionTop(); // 快捷搜索栏
    getMyCustomerTagsList({ type: 'crm' }); // 自定义标签
    doSearch({haveContacts:true}); // 列表搜索
    getRemindCount(); // 客户提醒
    getContactLogs();// 联系记录
    getSeasRight();
    getSearchAdForm();
  }

  componentWillReceiveProps(nextProps) {
    const keyOld = this.props.location.key;
    const keyNew = nextProps.location.key;
    // 点击菜单路由刷新组件
    if (keyOld !== keyNew) {
      const { mineCustomerStore } = nextProps;
      const { getMyCustomerTabs, doSearch, getRemindCount, getMyCustomerTagsList, conditionTop, getContactLogs, resetTable, getSeasRight } = mineCustomerStore;
      mineCustomerStore.clearStatus();
      getMyCustomerTabs(); // 获取tab页签
      conditionTop(); // 快捷搜索栏
      getMyCustomerTagsList({ type: 'crm' }); // 自定义标签
      doSearch({haveContacts:true}); // 列表搜索
      getRemindCount(); // 客户提醒
      getContactLogs();
      resetTable();
      getSeasRight();
    }
  }
    createHeight = () => {
      const contentH = jQuery('.wea-new-top-req-content').height() - 1;
      return contentH;
    }
    componentWillUnmount() {
      const { mineCustomerStore } = this.props;
      mineCustomerStore.clearStatus();
    }
    render() {
      const { mineCustomerStore, location } = this.props;
      let { title, loading, remindCount, tabDatas, searchBaseParams, showRight, dateSelect, rightTabData, rightTabKey, cardloading, tagDatas, contactLogs, contactLogsTotal, contacterCard, contacterTotal, leaveMessage, leaveMessageTotal, sellChanceCard, sellChanceCardTotal, rightInfos, cardManageStore, seasDialog } = mineCustomerStore;
      title = getLabel(6059, '我的客户');
      rightTabData = [{ key: 1, title: getLabel(6082, '客户联系') }, { key: 2, title: getLabel(572, '联系人') }, { key: 3, title: getLabel(84344, '客户留言') }, { key: 4, title: getLabel(2227, '销售机会') }]; // 右边栏tab


      const dialogButtons = [];
      const disabled = (seasDialog.seasIds == '');
      dialogButtons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@uufalr@save`} type="primary" onClick={() => mineCustomerStore.joinSeas()} disabled={disabled}>{getLabel(86, '保存')}</Button>);
      dialogButtons.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@1qrdnp@close`} onClick={() => mineCustomerStore.showSeasDialog(false)}>{getLabel(309, '关闭')}</Button>);

      const dialogMenus = [];
      dialogMenus.push({
        key: '1',
        icon: <i className="icon-coms-Preservation" />,
        content: getLabel(86, '保存'),
        onClick: () => mineCustomerStore.joinSeas(),
        disabled,
      });
      dialogMenus.push({
        key: '2',
        icon: <i className="icon-coms-go-back" />,
        content: getLabel(309, '关闭'),
        onClick: () => mineCustomerStore.showSeasDialog(false),
      });
      const tabs = [];
      toJS(tabDatas).map((item) => {
        const { key } = item;
        if (key == 'my' || key == 'all' || key == 'attention') {
          tabs.push(item);
        } else {
          const { key, labelOrder, labelType, id, title, textColor, isUsed, labelColor } = item;
          const tagitem = {};
          tagitem.key = key;
          tagitem.title = <WeaTag ecId={`${this && this.props && this.props.ecId || ''}_WeaTag@n650v9@${key}`} color={labelColor} >{title}</WeaTag>;
          tagitem.titleText = title;
          tabs.push(tagitem);
        }
      });
      // console.log(tabs)
      return (
        <div>
          <WeaRightMenu
            ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@lbsfao`}
            datas={this.getRightMenu()}
            onClick={this.onRightMenuClick.bind(this)}
            collectParams={{
              favname: title,
              favouritetype: 4,
              importantlevel: 1,
              objid: -1,
            }}
          >
            <WeaTop
              ecId={`${this && this.props && this.props.ecId || ''}_WeaTop@c0nzkl`}
              title={title}
              loading={loading}
              icon={<i className="icon-coms-crm" />}
              iconBgcolor="#96358a"
              buttonSpace={10}
              showDropIcon
              dropMenuDatas={this.getRightMenu()}
              onDropMenuClick={this.onRightMenuClick.bind(this)}
              buttons={this.getButtons()}
            >
              <WeaTab
                ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@i8q8io`}
                selectedKey={searchBaseParams.labelid}
                keyParam="key" // 主键
                countParam="groupid" // 数量
                onChange={this.changeData.bind(this)}
                datas={tabs}
              />
              <WeaRightLeftLayout ecId={`${this && this.props && this.props.ecId || ''}_WeaRightLeftLayout@0tgmpk`} type={10} defaultShowLeft={false} onClick={(v) => { mineCustomerStore.showRightChange(v); }} leftCom={this.getCustomerTable()} >
                {
                  !showRight &&
                  <div className="crm-right-tab">
                    <div className="sellchancemain-right-top">
                      <WeaSelect
                        ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@5tlaui`}
                        value={dateSelect.datatype}
                        options={[{ key: '1', selected: true, showname: getLabel(83223, '近一月') },
                          { key: '2', selected: false, showname: getLabel(83224, '近三月') },
                          { key: '3', selected: false, showname: getLabel(84343, '近半年') },
                          { key: '4', selected: false, showname: getLabel(83225, '近一年') },
                          { key: '0', selected: false, showname: getLabel(332, '全部') }]}
                        onChange={this.dateSelectChange.bind(this)}
                      />
                    </div>
                    <WeaTab
                      ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@jtlwev`}
                      selectedKey={rightTabKey}
                      datas={toJS(rightTabData)}
                      keyParam="key"
                      onChange={this.changeRightTab.bind(this)}
                    />
                    {
                      rightTabKey == '1' &&
                      <div className="contact-logs-container">
                        <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@ew8gmk`} spinning={cardloading} >
                          <ViewContactLog ecId={`${this && this.props && this.props.ecId || ''}_ViewContactLog@uith6h`} data={toJS(contactLogs)} total={contactLogsTotal} pageChange={(num) => { mineCustomerStore.getContactLogs({ pageNum: num }); }} />
                        </Spin>
                      </div>
                    }
                    {
                      rightTabKey == '2' &&
                      <div className="contact-logs-container">
                        <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@8l9rrh`} spinning={cardloading} >
                          <ViewContacter ecId={`${this && this.props && this.props.ecId || ''}_ViewContacter@spskg2`} data={toJS(contacterCard)} total={contacterTotal} pageChange={(num) => { mineCustomerStore.getContacterCard({ pageNum: num }); }} />
                        </Spin>
                      </div>
                    }
                    {
                      rightTabKey == '3' &&
                      <div className="contact-logs-container">
                        <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@ddnidr`} spinning={cardloading} >
                          <ViewLeaveMessage ecId={`${this && this.props && this.props.ecId || ''}_ViewLeaveMessage@hbpzfv`} data={toJS(leaveMessage)} total={leaveMessageTotal} pageChange={(num) => { mineCustomerStore.getLeaveMessage({ pageNum: num }); }} />
                        </Spin>
                      </div>
                    }
                    {
                      rightTabKey == '4' &&
                      <div className="contact-logs-container">
                        <Spin ecId={`${this && this.props && this.props.ecId || ''}_Spin@doum2a`} spinning={cardloading} >
                          <ViewSellChance ecId={`${this && this.props && this.props.ecId || ''}_ViewSellChance@pi8lpr`} data={toJS(sellChanceCard)} total={sellChanceCardTotal} pageChange={(num) => { mineCustomerStore.getSellchanceCard({ pageNum: num }); }} />
                        </Spin>
                      </div>
                    }
                  </div>
                }
                {
                  showRight && <CardManage
                    ecId={`${this && this.props && this.props.ecId || ''}_CardManage@deebf3`}
                    contentStore={cardManageStore}
                    paramsData={{ from: 'mine', customerId: rightInfos.customerId, ...searchBaseParams }}
                    rightInfos={toJS(rightInfos)}
                    type="minecustomer"
                  />
                }
              </WeaRightLeftLayout>
            </WeaTop>

          </WeaRightMenu>
          <SetTagModal ecId={`${this && this.props && this.props.ecId || ''}_SetTagModal@ph2531`} ref="setTagModal" data={toJS(tagDatas)} contentStore={mineCustomerStore} type={'crm'} />
          {seasDialog.visible && <WeaDialog
            ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@zcm6sv`}
            buttons={dialogButtons}
            title={seasDialog.title}
            iconBgcolor="#96358a"
            icon="icon-coms-crm"
            visible={seasDialog.visible}
            onCancel={() => mineCustomerStore.showSeasDialog(false)}
            style={{ width: 750, height: 415 }}
            hasScroll
          >
            <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@p1v1ec`} datas={dialogMenus}>
              {seasDialog.contents && seasDialog.contents.length > 0 ? <div style={{ width: '90%', margin: '0 auto' }}><WeaTransfer ecId={`${this && this.props && this.props.ecId || ''}_WeaTransfer@lu5g35`} data={toJS(seasDialog.contents)} selectedKeys={toJS(seasDialog.seasIds)} onChange={(keys, datas) => mineCustomerStore.setSeasIds(keys, datas)} renderItem={this.getRenderItem} /></div>
                :
                <div style={{ position: 'relative', height: 280 }}>
                <WeaAlertPage ecId={`${this && this.props && this.props.ecId || ''}_WeaAlertPage@0adkpl`}>
                    <div style={{ color: '#000' }}>
                    {getLabel('386711', '暂无公海供您选择，请联系管理员！')}
                  </div>
                  </WeaAlertPage>
              </div>
              }
            </WeaRightMenu>
          </WeaDialog>}
        </div>
      );
    }
    getRenderItem = item => (<div className="tree-title">
      <div style={{ float: 'left', width: '70%', overflow: 'hidden', textOverflow: 'ellipsis' }}>{item.name || '--'}</div> <div style={{ width: '30%', overflow: 'hidden', textOverflow: 'ellipsis' }}>{item.manager || '--'}</div>
    </div>)

    changeData = (key) => {
      const { doSearch, conditionTop, istorefresh, updateParams, getContactLogs } = this.props.mineCustomerStore;
      updateParams();
      conditionTop({ labelid: key });
      doSearch({ labelid: key });
      getContactLogs({ labelid: key });
    }
    getCustomerTable() {
      const { mineCustomerStore } = this.props;
      const { tableStore, reLoad, doSearch, searchBaseParams, selectedRowKeys, form, condition, updateBase, searchsBaseKey } = mineCustomerStore;
      const { isFormInit } = form;
      const group = [];
      isFormInit && toJS(condition).map((c,indexGroup) => {
        const items = [];
        c.items.map((field,index) => {
          let col = 2;
          if (field.conditionType.toUpperCase() == WeaTools.types.CASCADER) col = 1;
          if (field.domkey[0] == 'name') {
            items.push({
              com: (<WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@4dwlgy@${index}`}
                label={`${field.label}`}
                labelCol={{ span: `${field.labelcol}` }}
                ratio1to2
                error={form.getError(field)}
                tipPosition="bottom"
                wrapperCol={{ span: `${field.fieldcol}` }}
              >
                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@cbm2p7@${index}`} fieldConfig={field} form={form} onChange={(v) => { updateBase(v.name.value); }} onEnterSearch={this.onEnterSearch} />
              </WeaFormItem>),
              col,
              hide: form.isHide(field, (keys, allParams) => false),
            });
          } else {
            items.push({
              com: (<WeaFormItem
                ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@lp28rv@${index}`}
                label={`${field.label}`}
                labelCol={{ span: `${field.labelcol}` }}
                ratio1to2
                error={form.getError(field)}
                tipPosition="bottom"
                wrapperCol={{ span: `${field.fieldcol}` }}
              >
                <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@to2yqc@${index}`} fieldConfig={field} form={form} onEnterSearch={this.onEnterSearch} />
              </WeaFormItem>),
              col,
              hide: form.isHide(field, (keys, allParams) => false),
            });
          }
        });
        group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@voo9hw@${indexGroup}`} needTigger={false} title={c.title} showGroup={c.defaultshow} items={items} />);
      });

      return (
        <div id="crm-tab-dropdown" >
          <WeaCrmTab
            ecId={`${this && this.props && this.props.ecId || ''}_WeaCrmTab@9k0j3x`}
            searchType={['base', 'advanced']}
            selectGroups={this.getSelectGroups()}
            searchsBaseValue={isFormInit ? form.getFormParams()[searchsBaseKey] : ''}
            onSearch={(v) => { doSearch({ [searchsBaseKey]: v }); }}
            onSearchChange={(v) => {
              if (form.has(searchsBaseKey)) {
                form.updateFields({ [searchsBaseKey]: { value: v } }, false);
              }
            }}
            hasDropMenu
            buttons={this.getSeasButtons()}
            setShowSearchAd={(bool) => {
              this.setState({
                showSearchAd: bool,
              });
            }}
            searchsAd={
              <div className="crm-mine-query-condition">
                {group}
              </div>
            }
            buttonsAd={this.getSearchButtons()}
            showSearchAd={this.state.showSearchAd}
            // onSearchChange={v=>{actions.saveOrderFields({...orderFields.toJS(),...{name:{name:'name',value:v}}})}}
          />
          <WeaTable
            ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@68ae05`}
            comsWeaTableStore={tableStore}
            hasOrder
            needScroll
            register_table={reLoad}
            getColumns={c => this.reRenderColumns(c)}
            needRowClick
            tableWidth={this.getTableWidth.bind(this)}
            onRowClick={this.onClickRow}
          />
        </div>
      );
    }

    // 选中行
    onClickRow = (record) => {
      this.viewCustomerDetail(record.randomFieldId);
    }

    getSearchButtons() {
      const { mineCustomerStore } = this.props;
      const { clearFormFields, doSearch, form } = mineCustomerStore;
      const btnStyle = { borderRadius: 3, height: 28, width: 80 };
      return [
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@4lqzqm@search`} type="primary" style={btnStyle} onClick={() => { doSearch(); this.setState({ showSearchAd: false }); }}>{getLabel(197, '搜索')}</Button>),
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@fwblvo@reset`} type="ghost" style={btnStyle} onClick={() => { clearFormFields(); }}>{getLabel(2022, '重置')}</Button>),
        (<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@83vbst@cancel`} type="ghost" style={btnStyle} onClick={() => { this.setState({ showSearchAd: false }); }}>{getLabel(201, '取消')}</Button>),
      ];
    }

    reRenderColumns(columns) {
      const { mineCustomerStore } = this.props;
      const that = this;
      const styleObj = { width: '100%' };
      columns.forEach((c) => {
        if (c.dataIndex == 'name') {
          c.render = function (text, record) {
            return <div><span dangerouslySetInnerHTML={{ __html: record.namespan }} /></div>;
          };
        } else if (c.dataIndex == 'important') {
          c.render = function (text, record) {
            return <div><span><Rate ecId={`${this && this.props && this.props.ecId || ''}_Rate@r1rh60`} count={1} value={text} onChange={(text) => { that.focusOnClick(record.important, record.randomFieldId); }} /></span></div>;
          };
        } else {
          c.render = function (text, record) {
            const valueSpan = record[`${c.dataIndex}span`] !== undefined ? record[`${c.dataIndex}span`] : record[c.dataIndex];
            return <div style={styleObj}><span dangerouslySetInnerHTML={{ __html: valueSpan }} /></div>;
          };
        }
      });
      return columns;
    }

    focusOnClick = (num, id) => { // 点击星星
      let flag = 1;
      if (num == '1') { flag = 0; }
      this.markTagsTo(flag, id);
    }

    markTagsTo(i, key) { // 重要  取消重要
      const { isMarkToImportant, doSearch } = this.props.mineCustomerStore;
      isMarkToImportant({ relatedIds: key, important: i, type: 'crm' });
    }

    getSeasButtons() {
      const { mineCustomerStore } = this.props;
      const { searchBaseParams, tableStore, hasSeasRight } = mineCustomerStore;
      const btnArr = [];
      // if ('my' == searchBaseParams.labelid || (hasSeasRight && 'my' != searchBaseParams.labelid)) {
      //     const disabled = tableStore.selectedRowKeys.length == 0;
      //     btnArr.push(<Button type="primary" disabled={disabled} onClick={() => mineCustomerStore.getRightSeas()}>{getLabel('386712', "加入公海")}</Button>);
      // }

      return btnArr;
    }

    getButtons() {
      const { isPro, remindCount, birthdayCount } = this.props.mineCustomerStore;
      const btnArr = [];
      if (isPro) {
        // 正式
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@6r5l71@create`} type="primary" onClick={() => openFullWindowHaveBar('/CRM/data/AddCustomerFrame.jsp?tabtype=add')}>
          <i className="icon-coms-New-customer" /> {getLabel(82, '新建')}
        </Button>);
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@o3tteu@import`} type="primary" onClick={() => openFullWindowHaveBar('/CRM/data/AddCustomerFrame.jsp?tabtype=import')}>
          <i className="icon-crm-customerimport" /> {getLabel(18596, '导入')}
        </Button>);
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@9uvyxq@birthdayRemind`} type="primary" onClick={() => openFullWindowHaveBarForCrm('/main/crm/birthday')}>
          <i className="icon-coms-birthday" /> {getLabel(17534, '生日提醒')}{`(${birthdayCount})`}
        </Button>);
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@2alj8t@contactRemind`} type="primary" onClick={() => openFullWindowHaveBarForCrm('/main/crm/contact?tabtype=remind')}>
          <i className="icon-coms-contact" /> {getLabel(16403, '联系提醒')}{`(${remindCount})`}
        </Button>,
        );
      } else {
        // 标准
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@l1r42h@create`} type="primary" onClick={() => openFullWindowHaveBarForCrm('/main/crm/addCustomer?type=1')}>
          <i className="icon-coms-New-customer" /> {getLabel(82, '新建')}
        </Button>);
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@regxp6@import`} type="primary" onClick={() => openFullWindowHaveBarForCrm('/main/crm/addCustomer?type=2')}>
          <i className="icon-crm-customerimport" />  {getLabel(18596, '导入')}
        </Button>);
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@g6gnni@birthdayRemind`} type="primary" onClick={() => openFullWindowHaveBarForCrm('/main/crm/birthday')}>
          <i className="icon-coms-birthday" /> {getLabel(17534, '生日提醒')}{`(${birthdayCount})`}
        </Button>);
        btnArr.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@8z83ku@contactRemind`} type="primary" onClick={() => openFullWindowHaveBarForCrm('/main/crm/contact?tabtype=remind')}>
          <i className="icon-coms-contact" />  {getLabel(16403, '联系提醒')}{`(${remindCount})`}
        </Button>);
      }
      return btnArr;
    }
    getRightMenu() {
      // btns.push({
      // 	icon: <i className='icon-coms-Collection'/>,
      // 	content:getLabel(28111,'收藏')
      // });
      // btns.push({
      //     icon: <i className='icon-coms-help'/>,
      //     content:getLabel(275,'帮助'),
      // })
      const { mineCustomerStore } = this.props;
      const { searchBaseParams, tableStore, hasSeasRight } = mineCustomerStore;
      const btnArr = [];
      if (searchBaseParams.labelid == 'my' || (hasSeasRight && searchBaseParams.labelid != 'my')) {
        const disabled = tableStore.selectedRowKeys.length == 0;
        btnArr.push({
          key: 2,
          disabled,
          icon: <i className="icon-coms-redo" />,
          content: getLabel('386712', '加入公海'),
        });
      }
      return btnArr;
    }
    onRightMenuClick(key) {
      const { actions, comsWeaTable, dataKey, mineCustomerStore } = this.props;
      if (key == '0') {

      }
      if (key == '1') {
        // actions.batchSubmitClick({checkedKeys:`${selectedRowKeys.toJS()}`})
      }
      if (key == 2) {
        mineCustomerStore.getRightSeas();
      }
    }
    getSelectGroups=() => {
      const { hrmList, viewTypeList, statusOptions, isShowResource, sectorTreeData, istorefresh, tagDatas, tableStore, quickList, contactOptions, quickConditions } = this.props.mineCustomerStore;
      const { selectedRowKeys } = tableStore;
      const statusOptions1 = toJS(statusOptions);
      const sectorTreeData1 = toJS(sectorTreeData);
      const that = this;
      const tabs = [];

      tabs.push(
        <TabPane
          ecId={`${this && this.props && this.props.ecId || ''}_TabPane@rmjvyu@tp`}
          tab={
            <WeaDropdown
              ecId={`${this && this.props && this.props.ecId || ''}_WeaDropdown@gm10ji@dropdown`}
              defaultValue={getLabel(176, '标签')}
              type="tag"
              datas={toJS(tagDatas)}
              selectKeys={`${toJS(selectedRowKeys)}`}
              markTagsTo={that.markTagsTo.bind(that)}
              markToCustomTag={that.markToCustomTag.bind(that)}
              setting={that.setting.bind(that)}
              layout="crm-tab-dropdown"
            />
          }
          key="5"
        />,
      );
      if (isShowResource) {
        const k1 = 'resourceid';
        tabs.push(
          <TabPane
            ecId={`${this && this.props && this.props.ecId || ''}_TabPane@yltuso@tp`}
            tab={
              <WeaDropdown
                ecId={`${this && this.props && this.props.ecId || ''}_WeaDropdown@b9yi8n@dropdown`}
                value={quickConditions[k1]}
                valueSpan={quickConditions[`${k1}span`]}
                keyValue={k1}
                defaultValue={toJS(hrmList).length > 0 ? toJS(hrmList)[0].name : ''}
                type="tree"
                datas={toJS(hrmList)}
                hrmListChange={that.onHrmListChange}
                onChange={(obj) => { this.selectChange(obj, { quickSign: k1, quickSearch: k1 }); }}
                layout="crm-tab-dropdown"
              />
            }
            key="1"
          />,
        );
        const k2 = 'viewtype';
        tabs.push(
          <TabPane
            ecId={`${this && this.props && this.props.ecId || ''}_TabPane@d3cce7@tp`}
            tab={
              <WeaDropdown
                ecId={`${this && this.props && this.props.ecId || ''}_WeaDropdown@ks1fdg@dropdown`}
                value={quickConditions[k2]}
                valueSpan={quickConditions[`${k2}span`]}
                keyValue={k2}
                defaultValue={toJS(viewTypeList)[0].name}
                type="select"
                datas={toJS(viewTypeList)}
                onChange={(obj) => { this.selectChange(obj, { quickSign: k2, quickSearch: k2 }); }}
                layout="crm-tab-dropdown"
              />
            }
            key="2"
          />,
        );
      }
      const k3 = 'contactTime_str';
      tabs.push(
        <TabPane
          ecId={`${this && this.props && this.props.ecId || ''}_TabPane@r2ftvc@tp`}
          tab={
            <WeaDropdown
              ecId={`${this && this.props && this.props.ecId || ''}_WeaDropdown@co2yfc@dropdown`}
              layout="crm-tab-dropdown"
              value={quickConditions[k3]}
              valueSpan={quickConditions[`${k3}span`]}
              keyValue={k3}
              defaultValue={getLabel(16405, '联系情况')}
              type="select"
              datas={toJS(contactOptions)}
              onChange={(obj) => { this.selectChange(obj, { quickSign: k3, quickSearch: k3 }); }}
            />
          }
          key="7"
        />,
      );

      for (const quickMap of quickList) {
        if (quickMap.quickSign && quickMap.quickSign == 'sector') {
          tabs.push(
            <TabPane
              ecId={`${this && this.props && this.props.ecId || ''}_TabPane@zq795n@tp`}
              tab={
                <WeaDropdown
                  ecId={`${this && this.props && this.props.ecId || ''}_WeaDropdown@zkrvob@dropdown`}
                  layout="crm-tab-dropdown"
                  keyValue={quickMap.quickSearch}
                  value={quickConditions[quickMap.quickSearch]}
                  valueSpan={quickConditions[`${quickMap.quickSearch}span`]}
                  defaultValue={sectorTreeData1[0].name || ''}
                  type="tree"
                  datas={sectorTreeData1}
                  onChange={(obj) => { this.selectChange(obj, quickMap); }}
                  hrmListChange={that.industryChange}
                />
              }
              key="4"
            />,
          );
        } else {
          tabs.push(
            <TabPane
              ecId={`${this && this.props && this.props.ecId || ''}_TabPane@cq2hwi@$tp`}
              tab={
                <WeaDropdown
                  ecId={`${this && this.props && this.props.ecId || ''}_WeaDropdown@vgvcav@dropdown`}
                  layout="crm-tab-dropdown"
                  keyValue={quickMap.quickSearch}
                  value={quickConditions[quickMap.quickSearch]}
                  valueSpan={quickConditions[`${quickMap.quickSearch}span`]}
                  defaultValue={quickMap.quickName}
                  type={quickMap.multiple ? 'selectMultiple' : 'select'}
                  datas={quickMap.quickOptions}
                  onChange={(obj) => { this.selectChange(obj, quickMap); }}
                />
              }
              key={quickMap.quickKey}
            />,
          );
        }
      }
      return <Tabs ecId={`${this && this.props && this.props.ecId || ''}_Tabs@a3s6ss`} defaultActiveKey="" key={istorefresh}>{tabs}</Tabs>;
    }
    onHrmListChange = (arr) => {
      const { saveHrmList } = this.props.mineCustomerStore;
      saveHrmList(arr);
    }
    industryChange = (arr) => {
      const { saveIndustry } = this.props.mineCustomerStore;
      saveIndustry(arr);
    }
    selectChange(obj, quickMap) {
      const { doSearchQuick, getContactLogs, setRightTabKey, saveSelectValue } = this.props.mineCustomerStore;
      doSearchQuick(obj, quickMap);
      getContactLogs({ datatype: '1' });
      saveSelectValue('1');
      setRightTabKey('1', false);
    }
    markToCustomTag(lablestr, selectkey, type) { // 应用  取消某标签
      const { markToCustomTagType } = this.props.mineCustomerStore;
      markToCustomTagType({ relatedIds: selectkey, labelIds: lablestr, operationType: type, type: 'crm' });
    }
    setting() {
      this.refs.setTagModal.visible = true;
    }

    viewCustomerDetail = (id) => {
      const { viewCustomerDetail, tableStore } = this.props.mineCustomerStore;
      viewCustomerDetail(id);
    }
    dateSelectChange(val) {
      const { getContactLogs, getContacterCard, getLeaveMessage, getSellchanceCard, rightTabKey } = this.props.mineCustomerStore;
      if (rightTabKey == '1') { getContactLogs({ datatype: val }); }
      if (rightTabKey == '2') { getContacterCard({ datatype: val }); }
      if (rightTabKey == '3') { getLeaveMessage({ datatype: val }); }
      if (rightTabKey == '4') { getSellchanceCard({ datatype: val }); }
    }
    changeRightTab(key) {
      const { setRightTabKey } = this.props.mineCustomerStore;
      setRightTabKey(key);
    }

    onEnterSearch=() => {
      this.setState({ showSearchAd: false });
      const { mineCustomerStore } = this.props;
      mineCustomerStore.doSearch();
    }

    getTableWidth = (columns) => {
      const showLength = columns.filter(col => col.display == 'true').length;
      return 120 * showLength;// 也支持返回固定值，如果小于100%,不会生效。
    }

    needRowClick = (a) => {
      console.log(a);
    }
}

export default WeaTools.tryCatch(React,
  props => <WeaErrorPage ecId={`${this && this.props && this.props.ecId || ''}_WeaErrorPage@f641gq`} msg={props.error ? props.error : getLabel(129417, '服务器运行出错，请联系系统管理员！')} />,
  { error: '' },
)(MineCustomer);
